package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author fire'ge
 */
public class ArticleOperation {
    public static ResultSet checkArticles(Connection connection) throws SQLException {
        String sql = "select * from articles";
        PreparedStatement ps = connection.prepareStatement(sql);
        return ps.executeQuery();
    }

    public static ResultSet displayArticle(int id ,Connection connection) throws SQLException {
        String sql = "select * from articles where id = ?";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setInt(1,id);
        return ps.executeQuery();
    }
    public static boolean addArticle(String topic,String text,String author,Connection connection) throws SQLException {
        String sql = "insert into articles values(null,?,?,?)";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setNString(1,topic);
        ps.setNString(2,text);
        ps.setNString(3,author);
        int executeUpdate = ps.executeUpdate();
        return executeUpdate > 0;
    }
}
